//
// Int8.cpp for  in /home/jousse_f//workspace/C++/abstractVM
//
// Made by florian jousseau
// Login   <jousse_f@epitech.net>
//
// Started on  Mon Feb  6 11:47:11 2012 florian jousseau
// Last update Thu Feb 16 18:47:43 2012 florian jousseau
//

#include <sstream>
#include <cmath>
#include "Int8.hh"
#include "Double.hh"
#include "convert.hpp"

Int8::Int8(char nb, eOperandType type)
  : Number(nb), Type(type)
{
  this->setRepresentation();
}

Int8::Int8(const Int8 &other)
  : Number(other.getNumber()), Type(other.getType())
{
  this->setRepresentation();
}

Int8	&Int8::operator=(const Int8 &other)
{
  if (this != &other)
    {
      this->Number = other.getNumber();
      this->Type = other.getType();
      this->setRepresentation();
    }
  return *this;
}

std::string const	&Int8::toString() const
{
  return (this->Representation);
}

void	Int8::setRepresentation()
{
  std::stringstream	stream;

  stream << (int)this->Number;
  this->Representation = stream.str();
}

int	Int8::getPrecision() const
{
  return (INT8);
}

char	Int8::getNumber() const
{
  return (this->Number);
}

eOperandType	Int8::getType() const
{
  return (this->Type);
}

IOperand	*Int8::operator+(const IOperand &rhs) const
{
  IOperand *tmp = new Double(this->getNumber() + toNumber<double>(rhs.toString()), NOTHING);
  return (tmp);
}

IOperand	*Int8::operator-(const IOperand &rhs) const
{
  IOperand *tmp = new Double(this->getNumber() - toNumber<double>(rhs.toString()), NOTHING);
  return (tmp);
}

IOperand	*Int8::operator*(const IOperand &rhs) const
{
  IOperand *tmp = new Double(this->getNumber() * toNumber<double>(rhs.toString()), NOTHING);
  return (tmp);
}

IOperand	*Int8::operator/(const IOperand &rhs) const
{
  IOperand *tmp = new Double(this->getNumber() / toNumber<double>(rhs.toString()), NOTHING);
  return (tmp);
}

IOperand	*Int8::operator%(const IOperand &rhs) const
{
  double	res = (this->getNumber() - toNumber<double>(rhs.toString()) * floor(this->getNumber() / toNumber<double>(rhs.toString())));

  IOperand *tmp = new Double(res, NOTHING);
  return (tmp);
}

Int8::~Int8()
{

}
